
Imports System.Data
Imports System.Data.SqlClient


Namespace Ventas
Public Class ComprobanteDetalle

public Function Listar(ComprobanteDetalleId as integer) as Entity.Ventas.ComprobanteDetalle

Dim strNameProcedure as string = "up_Ven_ComprobanteDetalle_obtener"
Dim sqlReader As SqlDataReader = Nothing
Dim sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
dim objEnt as   entity.Ventas.ComprobanteDetalle
Try
            sqlCon.Open()
Dim sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
.CommandType = CommandType.StoredProcedure
                .Parameters.Add(New SqlParameter("@ComprobanteDetalleId", SqlDbType.Int)).Value =ComprobanteDetalleId
            End With
            sqlReader = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection)
If sqlReader.HasRows Then
While sqlReader.Read
 objEnt= new    entity.Ventas.ComprobanteDetalle
With objEnt
		.ComprobanteDetalleId = sqlReader("ComprobanteDetalleId").ToString
		.ComprobanteID = sqlReader("ComprobanteID").ToString
		.ProductoId = sqlReader("ProductoId").ToString
		.Cantidad = sqlReader("Cantidad").ToString
		.StockBase = sqlReader("StockBase").ToString
		.StockDespues = sqlReader("StockDespues").ToString
		.PrecioBase = sqlReader("PrecioBase").ToString
		.Precio = sqlReader("Precio").ToString
		.DescuentoID = sqlReader("DescuentoID").ToString
		.Descuento = sqlReader("Descuento").ToString
		.Estado = sqlReader("Estado").ToString
		.SubTotal = sqlReader("SubTotal").ToString
		.Total = sqlReader("Total").ToString
End With
  End While
  End IF
 Catch ex As Exception
Throw New Exception(ex.ToString)
Finally
 sqlReader.Dispose()
  sqlReader.Close()
  sqlReader = Nothing
  sqlCon.Dispose()
 sqlCon.Close()
 sqlCon = Nothing
 End Try
return objEnt

End Function


'***************************



public Function Listar(Opcion as string , _
		ComprobanteDetalleId as Integer, _
		ComprobanteID as Integer, _
		ProductoId as Integer, _
		Cantidad as Integer, _
		StockBase as Integer, _
		StockDespues as Integer, _
		PrecioBase as Double, _
		Precio as Double, _
		DescuentoID as Integer, _
		Descuento as Double, _
		Estado as Integer, _
		SubTotal as Double, _
		Total as Double) _
as  Entity.Ventas.ComprobanteDetalleCol

Dim strNameProcedure as string = "up_Ven_ComprobanteDetalle_listar"
dim objCol as   entity.Ventas.ComprobanteDetalleCol
Try
Using conn As New SqlConnection(Configuracion.Connexion.Cnn)
Dim cmd As New SqlCommand(strNameProcedure, conn)
cmd.CommandType = CommandType.StoredProcedure
  cmd.Parameters.Add(New SqlParameter("@opcion", SqlDbType.varchar,50)).Value =Opcion
 cmd.Parameters.Add(New SqlParameter("@ComprobanteDetalleId",SqlDbType.INT)).Value =ComprobanteDetalleId
 cmd.Parameters.Add(New SqlParameter("@ComprobanteID",SqlDbType.INT)).Value =ComprobanteID
 cmd.Parameters.Add(New SqlParameter("@ProductoId",SqlDbType.INT)).Value =ProductoId
 cmd.Parameters.Add(New SqlParameter("@Cantidad",SqlDbType.INT)).Value =Cantidad
 cmd.Parameters.Add(New SqlParameter("@StockBase",SqlDbType.INT)).Value =StockBase
 cmd.Parameters.Add(New SqlParameter("@StockDespues",SqlDbType.INT)).Value =StockDespues
 cmd.Parameters.Add(New SqlParameter("@PrecioBase",SqlDbType.DECIMAL,18)).Value =PrecioBase
 cmd.Parameters.Add(New SqlParameter("@Precio",SqlDbType.DECIMAL,18)).Value =Precio
 cmd.Parameters.Add(New SqlParameter("@DescuentoID",SqlDbType.INT)).Value =DescuentoID
 cmd.Parameters.Add(New SqlParameter("@Descuento",SqlDbType.DECIMAL,18)).Value =Descuento
 cmd.Parameters.Add(New SqlParameter("@Estado",SqlDbType.SMALLINT)).Value =Estado
 cmd.Parameters.Add(New SqlParameter("@SubTotal",SqlDbType.DECIMAL,18)).Value =SubTotal
 cmd.Parameters.Add(New SqlParameter("@Total",SqlDbType.DECIMAL,18)).Value =Total
conn.Open()
Using dr As SqlDataReader = cmd.ExecuteReader()
		dim iComprobanteDetalleId as integer = dr.GetOrdinal("ComprobanteDetalleId")
		dim iComprobanteID as integer = dr.GetOrdinal("ComprobanteID")
		dim iProductoId as integer = dr.GetOrdinal("ProductoId")
		dim iCantidad as integer = dr.GetOrdinal("Cantidad")
		dim iStockBase as integer = dr.GetOrdinal("StockBase")
		dim iStockDespues as integer = dr.GetOrdinal("StockDespues")
		dim iPrecioBase as integer = dr.GetOrdinal("PrecioBase")
		dim iPrecio as integer = dr.GetOrdinal("Precio")
		dim iDescuentoID as integer = dr.GetOrdinal("DescuentoID")
		dim iDescuento as integer = dr.GetOrdinal("Descuento")
		dim iEstado as integer = dr.GetOrdinal("Estado")
		dim iSubTotal as integer = dr.GetOrdinal("SubTotal")
		dim iTotal as integer = dr.GetOrdinal("Total")
		dim i_usu_cre as integer = dr.GetOrdinal("_usu_cre")
		dim i_fec_cre as integer = dr.GetOrdinal("_fec_cre")
		dim i_usu_mod as integer = dr.GetOrdinal("_usu_mod")
		dim i_fec_mod as integer = dr.GetOrdinal("_fec_mod")
		dim i_flg_eli as integer = dr.GetOrdinal("_flg_eli")

 Dim colCount As Integer = dr.FieldCount
 Dim values As Object() = New Object(colCount - 1) {}

 objCol =  New entity.Ventas.ComprobanteDetalleCol
  If dr.HasRows Then
While dr.Read()
dim objEnt =  new entity.Ventas.ComprobanteDetalle
dr.GetValues(values)

		objEnt.ComprobanteDetalleId = values(iComprobanteDetalleId)
		objEnt.ComprobanteID = values(iComprobanteID)
		objEnt.ProductoId = values(iProductoId)
		objEnt.Cantidad = values(iCantidad)
		objEnt.StockBase = values(iStockBase)
		objEnt.StockDespues = values(iStockDespues)
		objEnt.PrecioBase = values(iPrecioBase)
		objEnt.Precio = values(iPrecio)
		objEnt.DescuentoID = values(iDescuentoID)
		objEnt.Descuento = values(iDescuento)
		objEnt.Estado = values(iEstado)
		objEnt.SubTotal = values(iSubTotal)
		objEnt.Total = values(iTotal)
 objCol.Add(objEnt)
 End While
 End if
 End Using
 End Using
 Catch ex As Exception
Throw New Exception(ex.ToString)
Finally
 End Try
return objCol

End Function


'***************************


Public  Function Insert(ByVal opcion As String, _
		ComprobanteDetalleId as Integer, _
		ComprobanteID as Integer, _
		ProductoId as Integer, _
		Cantidad as Integer, _
		StockBase as Integer, _
		StockDespues as Integer, _
		PrecioBase as Double, _
		Precio as Double, _
		DescuentoID as Integer, _
		Descuento as Double, _
		Estado as Integer, _
		SubTotal as Double, _
		Total as Double, _
vUsuario as integer ) As Integer

 dim strNameProcedure as string ="Up_Ven_ComprobanteDetalle_Insertar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
 .Parameters.Add(New SqlParameter("@ComprobanteDetalleId",SqlDbType.INT)).Value =ComprobanteDetalleId
 .Parameters.Add(New SqlParameter("@ComprobanteID",SqlDbType.INT)).Value =ComprobanteID
 .Parameters.Add(New SqlParameter("@ProductoId",SqlDbType.INT)).Value =ProductoId
 .Parameters.Add(New SqlParameter("@Cantidad",SqlDbType.INT)).Value =Cantidad
 .Parameters.Add(New SqlParameter("@StockBase",SqlDbType.INT)).Value =StockBase
 .Parameters.Add(New SqlParameter("@StockDespues",SqlDbType.INT)).Value =StockDespues
 .Parameters.Add(New SqlParameter("@PrecioBase",SqlDbType.DECIMAL,18)).Value =PrecioBase
 .Parameters.Add(New SqlParameter("@Precio",SqlDbType.DECIMAL,18)).Value =Precio
 .Parameters.Add(New SqlParameter("@DescuentoID",SqlDbType.INT)).Value =DescuentoID
 .Parameters.Add(New SqlParameter("@Descuento",SqlDbType.DECIMAL,18)).Value =Descuento
 .Parameters.Add(New SqlParameter("@Estado",SqlDbType.SMALLINT)).Value =Estado
 .Parameters.Add(New SqlParameter("@SubTotal",SqlDbType.DECIMAL,18)).Value =SubTotal
 .Parameters.Add(New SqlParameter("@Total",SqlDbType.DECIMAL,18)).Value =Total
 .Parameters.Add(New SqlParameter("@_usuario", SqlDbType.Int)).Value = vUsuario
 .Parameters.Add(New SqlParameter("@_fecha", SqlDbType.BigInt)).Value = now.tofiletime()
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************


Public  Function Update(ByVal opcion As String, _
		ComprobanteDetalleId as Integer, _
		ComprobanteID as Integer, _
		ProductoId as Integer, _
		Cantidad as Integer, _
		StockBase as Integer, _
		StockDespues as Integer, _
		PrecioBase as Double, _
		Precio as Double, _
		DescuentoID as Integer, _
		Descuento as Double, _
		Estado as Integer, _
		SubTotal as Double, _
		Total as Double, _
vUsuario as integer ) As Integer

 dim strNameProcedure as string ="Up_Ven_ComprobanteDetalle_Actualizar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
 .Parameters.Add(New SqlParameter("@ComprobanteDetalleId",SqlDbType.INT)).Value =ComprobanteDetalleId
 .Parameters.Add(New SqlParameter("@ComprobanteID",SqlDbType.INT)).Value =ComprobanteID
 .Parameters.Add(New SqlParameter("@ProductoId",SqlDbType.INT)).Value =ProductoId
 .Parameters.Add(New SqlParameter("@Cantidad",SqlDbType.INT)).Value =Cantidad
 .Parameters.Add(New SqlParameter("@StockBase",SqlDbType.INT)).Value =StockBase
 .Parameters.Add(New SqlParameter("@StockDespues",SqlDbType.INT)).Value =StockDespues
 .Parameters.Add(New SqlParameter("@PrecioBase",SqlDbType.DECIMAL,18)).Value =PrecioBase
 .Parameters.Add(New SqlParameter("@Precio",SqlDbType.DECIMAL,18)).Value =Precio
 .Parameters.Add(New SqlParameter("@DescuentoID",SqlDbType.INT)).Value =DescuentoID
 .Parameters.Add(New SqlParameter("@Descuento",SqlDbType.DECIMAL,18)).Value =Descuento
 .Parameters.Add(New SqlParameter("@Estado",SqlDbType.SMALLINT)).Value =Estado
 .Parameters.Add(New SqlParameter("@SubTotal",SqlDbType.DECIMAL,18)).Value =SubTotal
 .Parameters.Add(New SqlParameter("@Total",SqlDbType.DECIMAL,18)).Value =Total
 .Parameters.Add(New SqlParameter("@_usuario", SqlDbType.Int)).Value = vUsuario
 .Parameters.Add(New SqlParameter("@_fecha", SqlDbType.BigInt)).Value = now.tofiletime()
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************


Public Shared Function Eliminar(ByVal opcion As String, ComprobanteDetalleId as integer, vusuario as integer) as integer

 dim strNameProcedure as string ="Up_Ven_ComprobanteDetalle_Eliminar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
                .Parameters.Add(New SqlParameter("@ComprobanteDetalleId", SqlDbType.Int)).Value =ComprobanteDetalleId
 .Parameters.Add(New SqlParameter("@_usuario", SqlDbType.Int)).Value = vUsuario
 .Parameters.Add(New SqlParameter("@_fecha", SqlDbType.BigInt)).Value = now.tofiletime()
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************



End Class



end namespace

